%%%-------------------------------------------------------------------
%% @doc mqeg_fetch public API
%% @end
%%%-------------------------------------------------------------------

-module(mqeg_fetch).

-include("debug.hrl").
-include_lib("amqp_client/include/amqp_client.hrl").

%% --------------------------------------------------------------------
%% External exports
%% --------------------------------------------------------------------
-export([fetch/1]).

%% ====================================================================
%% External functions
%% ====================================================================
fetch(Name) ->
    Connection      = mqeg_misc:get_singleton(connection),
    {ok, Channel}   = amqp_connection:open_channel(Connection),
    Get             = #'basic.get'{queue = Name, no_ack = false},

    Data            = amqp_channel:call(Channel, Get),
    {GetOK, Content}= Data,

    ?trace(GetOK),
    ?trace(Content),

    % 返回 ack 
    % #'basic.get_ok'{delivery_tag = Tag} = GetOK,
    % amqp_channel:cast(Channel, #'basic.ack'{delivery_tag = Tag}),

    amqp_channel:close(Channel),

    Content#amqp_msg.payload.


%% ====================================================================
%% Local functions
%% ====================================================================

